<!doctype html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns:v-model="http://www.w3.org/1999/xhtml" xmlns:v-demo="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .router-link-active {
            color:#f00;
        }
        pre {
            font-family: sans-serif;
            font-size: 1em;
            line-height:1.5em;
        }

    </style>
</head>
<body>

    <div id="app">

    </div>
</body>

<script src="../../../vender/vue@2.4.2.js"></script>
<script src="../../../vender/vue-router@2.7.0.js"></script>

<script>
    const Home={template:`<div class="home">
            <h2>Home</h2>
        </div>`
    };
    const Parent={
        template:`<div class="parent">
            <h2>Parent</h2>
            <ul>
                <li><router-link to="/parent/foo">Parent/foo</router-link></li>
                <li><router-link to="/parent/bar">Parent/bar</router-link></li>
            </ul>
            <transition :name="transitionName"><router-view class="child-view"></router-view></transition>
        </div>`,
        data(){
            return {
                transitionName:'slide-left'
            }
        },
        watch:{
            '$route'(to,from){
                let toDepth=to.path.split('/').length,fromDepth=from.path.split('/').length;
                this.transitionName=toDepth<fromDepth?'slide-right':'slide-left';
                console.log('transitionName:',this.transitionName);
            }
        }
    };
    const Default={template:'<div>Default.</div>'};
    const Foo={template:'<div>Foo.</div>'};
    const Bar={template:'<div>Bar.</div>'};


    const router=new VueRouter({
        routes:[
            {path:'/',component:Home},
            {
                path:'/parent',component:Parent,
                children:[
                    {path:'',component:Default},
                    {path:'foo',component:Foo},
                    {path:'bar',component:Bar}
                ]
            }
        ]
    });

    const app=new Vue({
        el:'#app',
        router,
        template:`<div>
            <h2>Transitions</h2>
            <ul>
                <li><router-link to="/">Home</router-link></li>
                <li><router-link to="/parent">Parent</router-link></li>
            </ul>
            <transition name="fade" mode="out-in"><router-view class="view"></router-view></transition>
        </div>`
    });



</script>
</html>